cmake_minimum_required(VERSION 3.14)
project(ctl)
set(LLVM_COV_PATH "llvm-conv-12")
if(CMAKE_BUILD_TYPE STREQUAL "coverage" OR CODE_COVERAGE)
    if("${CMAKE_C_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
        message("Building with llvm Code Coverage Tools")

        # Warning/Error messages
        if(NOT LLVM_COV_PATH)
            message(FATAL_ERROR "llvm-cov not found! Aborting.")
        endif()

        # set Flags
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")

    elseif(CMAKE_COMPILER_IS_GNUCXX)
        message("Building with lcov Code Coverage Tools")

        # Warning/Error messages
        if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
            message(WARNING "Code coverage results with an optimized (non-Debug) build may be misleading")
        endif()
        if(NOT LCOV_PATH)
            message(FATAL_ERROR "lcov not found! Aborting...")
        endif()
        if(NOT GENHTML_PATH)
            message(FATAL_ERROR "genhtml not found! Aborting...")
        endif()

        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
    else()
        message(FATAL_ERROR "Code coverage requires Clang or GCC. Aborting.")
    endif()
endif()
set (CMAKE_C_FLAGS " -Wall -Wconversion -Wextra -Werror -Wcast-qual -Wpointer-arith -Wshadow -Wno-unused-function -Wno-unused-parameter -Wconversion ${CMAKE_C_FLAGS} -fsanitize=address -static-libsan -g3")
include_directories(include)
include_directories(macro)
link_directories("../bt")
add_library(ctl src/vector.c src/rbtree.c src/hashset.c src/hashmap.c src/pair.c)
add_executable(main src/main.c)
add_executable(test_vector test/test_vector.c)
target_link_libraries(test_vector ctl dw bt)
add_executable(test_rbtree test/test_rbtree.c)
target_link_libraries(test_rbtree ctl dw bt)
add_executable(test_hashset test/test_hashset.c)
target_link_libraries(test_hashset ctl dw bt)
# target_link_libraries(main ctl dw asan)